package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.WaterPriceDetailBean;
import com.koron.css2.baseConfig.bean.WaterPriceLadderBean;
import com.koron.css2.baseConfig.mapper.WaterPriceMapper;
import com.koron.css2.baseConfig.queryBean.WaterPriceQueryBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

public class WaterPriceQueryLadder implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		// TODO Auto-generated method stub
		@SuppressWarnings("rawtypes")
		MessageBean<List> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", List.class);

		try { 
			WaterPriceQueryBean bean = JsonUtils.objectToPojo(req.getData(), WaterPriceQueryBean.class);
			WaterPriceMapper mapper = factory.getMapper(WaterPriceMapper.class);
			//查询用水价格明细
			List<WaterPriceDetailBean> waterPricDetailList = mapper.selectWaterPriceBetailByIdForRedRush(bean.getId());
			for (WaterPriceDetailBean waterPriceDetailBean : waterPricDetailList) {
				List<WaterPriceLadderBean> ladder = mapper.selectWaterPriceLadderById(waterPriceDetailBean.getId());
				waterPriceDetailBean.setLadders(ladder);
			}
			info.setData(waterPricDetailList);
		}catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription(e.getMessage());
			// TODO: handle exception
		}
		return info;
	}

}
